#ifndef SUPPLIERCOMPONENTSPAGE_H
#define SUPPLIERCOMPONENTSPAGE_H

#include <QWidget>
#include "../backend/component.h" // For ComponentNode, Component

// 向前声明
class QTableWidget;
class QPushButton;
class QLabel;
class QVBoxLayout;
class QHBoxLayout; // Added for button layout
class QHeaderView; // Added for table header
class QTableWidgetItem; // Added for table items
class QMessageBox; // Added for messages

class SupplierComponentsPage : public QWidget {
    Q_OBJECT

public:
    explicit SupplierComponentsPage(QWidget *parent = nullptr);
    ~SupplierComponentsPage();

    // 加载并显示特定供应商组件的方法
    void loadComponentsForSupplier(int supplierId, const QString& supplierName, ComponentNode* allComponentsHead);

signals:
    void backToSearchRequested(); // Signal to go back to the main search page
    void viewComponentDetailRequested(int componentId); // Signal to request MainWindow to show detail page

private slots:
    void onInternalBackButtonClicked();
    void onViewDetailButtonClicked();    // Slot for the "View Detail" button
    void onTableItemDoubleClicked(QTableWidgetItem* item); // Slot for double-click on table

private:
    void setupUi();
    void populateComponentsTable(); // Takes data from currentSupplierId and currentComponentListHead

    QLabel* titleLabel; 
    QTableWidget* componentsTable;
    QPushButton* backButton;
    QPushButton* viewDetailButton; 

    QVBoxLayout* mainLayout;
    
    ComponentNode* currentComponentListHead; // Head of the full component list
    int currentSupplierId;                   // ID of the supplier whose components are being shown
    QString currentSupplierName;             // Name of the current supplier
};

#endif // SUPPLIERCOMPONENTSPAGE_H